
package com.updesignsz.api.controller;

import com.updesignsz.api.service.TypeService;
import com.updesignsz.api.util.ResponseUtil;
import com.updesignsz.commom.util.ResultVo;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类型
 * Creation date 2020-8-8 15:02:24
 */
@RestController
@RequestMapping(value = "/api/type", method = RequestMethod.POST)
public class TypeController {

	@Autowired
	private TypeService typeService;

	/**
	 * 类型列表
	 */
	@RequestMapping(value = "/list")
	public void list(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ResultVo vo = new ResultVo();
		try {
			JSONObject json = ResponseUtil.getRequestAsJSONObject(request);
			json.put("table", json.optInt("type", 1) == 1 ? "projects" : "news");
			vo.setData(typeService.findByAll(json));
		} catch (Exception e) {
			e.printStackTrace();
		}
		ResponseUtil.outJson(vo.toJsonMsg(), response);
	}
}